package net.kts.util.network;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkCheck {
	public static final int WIFI_MODE=0; //Wi-Fi 모드일시반환값
	public static final int MOBILE_MODE=1; //3g 모드일시반환값
	public static final int CLOSE_MODE=2; //비접속시

	static public int check(Context context){

		ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		int mode=CLOSE_MODE;
		if (mobile.isConnected() || wifi.isConnected()){
			// WIFI, 3G 모드일시
			//Log.d(TAG, "Network connect success");
			if(wifi.isConnected()){
				mode= WIFI_MODE;
			}
			if(mobile.isConnected()){
				mode= MOBILE_MODE;
			}
		}else{
			mode= CLOSE_MODE;

		}

		manager = null;
		mobile = null;
		wifi = null;

		return mode;


	}
}
